import { defineStore } from 'pinia'
import { useStorage } from '@vueuse/core'

export const useUserStore = defineStore('user', () => {
  // 状态（优先从 localStorage 读取）
  const storedUser = useStorage('user', {
    id: '',
    username: '',
    idType: '',
    parentId: ''
  })

  /**
   * 更新用户信息
   */
  const updateUser = newData => {
    storedUser.value = { ...storedUser.value, ...newData }
  }

  return {
    user: storedUser,
    updateUser
  }
})
